<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
        $model=M('album');
        $list=$model->select();
        foreach($list as $key=>$value){
            $list[$key]['face']='/Public/Uploads/'.self::sub($value['face']).$value['face'];
        }
        $this->assign('list',$list);
        $this->display();
    }
    public function doalbum(){
        $data['name']=I('post.name');
        $filename=self::upload();
        if(!$data['name']){
            $this->error('上传有问题');
            return false;
        }
        $data['face']=$filename;
        $data['addTime']=time();
        $model=M('album');
        $res=$model->add($data);
        if($res){
            $this->redirect('Index/index');
        }else{
            $this->error('插入失败');
            return false;
        }
    }
    public function photo(){
        $pid=I('post.aid');
        $data['aid']=$pid;
        $filename=self::upload();
        $data['name']=$filename;
        $data['addTime']=time();
        $model=M('photo');
        $res=$model->add($data);
        if($res){
            $this->redirect('Index/index');
        }else{
            $this->error('插入失败');
            return false;
        }
    }
    public function intophoto(){
        $pid=I('post.pid');
        $modelphoto=M('photo');
        $data=$modelphoto->where('aid='.$pid)->select();
        foreach($data as $key=>$value){
            $data[$key]['name']='/Public/Uploads/'.self::sub($value['name']).$value['name'];
            $data[$key]['addtime']=date('Y年m月d日 H时i分',$value['addtime']);
        }
        $this->assign('data',$data);
        $this->display('Index/rp');
    }

    public function main(){
        session('name',null);
        header('location:http://mz0204.chediandi.com/');
    }


}